home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Tools / ClassAct / Demo / ClassActDemo.c < prev    next >
C/C++ Source or Header  |  1997-05-31  |  42KB  |  1,448 lines

  1.  
  2. /**
  3.  **  ClassAct Demonstration.
  4.  **
  5.  **  Copyright © 1995-1997 by Timothy Aston and Christopher Aldi
  6.  **  All rights reserved.
  7.  **
  8.  **  This is a fairly comprehensive demo intended to show-off ClassAct's
  9.  **  capability, and also demonstrate to you, the programmer, how to use
  10.  **  ClassAct.
  11.  **
  12.  **  The demo takes place completely in a single window, made up of several
  13.  **  pages.  The entire GUI layout is done completely in a single Layout
  14.  **  class gadget, that is made up of layout groups containing images and
  15.  **  gadgets and other layout groups.  We create this layout first, then we
  16.  **  create a window object and attach the layout to that.
  17.  **
  18.  **  A good idea would be to go through each of the gadgets created in this
  19.  **  programme, load up its autodoc, and see how we've used the various
  20.  **  features here in this demo.  Then feel free to change some things
  21.  **  around and see what else you can do with ClassAct, because this demo by
  22.  **  no means shows off all that ClassAct can do.
  23.  **
  24.  **/
  25.  
  26. #include <exec/types.h>
  27. #include <exec/memory.h>
  28. #include <dos/dos.h>
  29. #include <graphics/gfxbase.h>
  30. #include <intuition/intuition.h>
  31. #include <intuition/gadgetclass.h>
  32. #include <intuition/imageclass.h>
  33. #include <intuition/icclass.h>
  34. #include <gadgets/listbrowser.h>
  35. #include <images/label.h>
  36. #include <libraries/asl.h>
  37. #include <libraries/gadtools.h>
  38. #include <utility/tagitem.h>
  39. #include <proto/asl.h>
  40. #include <proto/dos.h>
  41. #include <proto/diskfont.h>
  42. #include <proto/exec.h>
  43. #include <proto/gadtools.h>
  44. #include <proto/graphics.h>
  45. #include <proto/icon.h>
  46. #include <proto/intuition.h>
  47. #include <proto/utility.h>
  48. #include <classact.h>
  49. #include <gadgets/getfile.h>
  50. #include <gadgets/getfont.h>
  51. #include <gadgets/getscreenmode.h>
  52. #include <proto/getfile.h>
  53. #include <proto/getfont.h>
  54. #include <proto/getscreenmode.h>
  55. #include "stdio.h"
  56. #include "strings.h"
  57.  
  58.  
  59. /* Some useful #defines.
  60.  */
  61. #define D(x)
  62. #define MAX(a, b) ((a > b) ? a : b)
  63. #define MIN(a, b) ((a > b) ? b : a)
  64. #define RED(x) ((x >> 8) & 0xf)
  65. #define BLUE(x) ((x >> 4) & 0xf)
  66. #define GREEN(x) (x & 0xf)
  67.  
  68. /* Gadget IDs
  69.  */
  70. #define GAD_BACK 1
  71. #define GAD_FORWARD 2
  72. #define GAD_QUIT 3
  73. #define GAD_GETFILE 4
  74. #define GAD_GETFONT 5
  75. #define GAD_GETSCREEN 6
  76.  
  77. #define NUM_PAGES 7
  78.  
  79.  
  80. extern struct GfxBase *GfxBase;
  81.  
  82. /* External variables, from Images.c
  83.  */
  84. extern struct Image picture_image, classact_image;
  85. extern struct Image sb_images[];
  86. extern struct Image hide_image, show_image, leaf_image;
  87.  
  88. /* Global variables.
  89.  */
  90. struct Screen *screen = NULL;
  91. struct Gadget *layout, *layout1, *page, *layout2;
  92. struct Gadget *fuelgauge_gad, *scroller_gad, *palette_gad, *lb_gad;
  93. struct Gadget *getfile_gad, *getfont_gad, *getscreen_gad, *fontpreview_gad;
  94. struct Gadget *back_gad, *forward_gad;
  95. struct Image *limage;
  96. struct List *radio_list, *chooser_list1, *chooser_list2, *chooser_list3, *tab_list;
  97. struct List speedbar_list, lb_list1, lb_list2;
  98.  
  99.  
  100. /* Some static string data used to initialize some gadgets.
  101.  */
  102.  
  103. /* Integer to FuelGauge mapping.
  104.  */
  105. struct TagItem integer_map[] =
  106. {
  107.     { INTEGER_Number, FUELGAUGE_Level },
  108.     { TAG_END, NULL }
  109. };
  110.  
  111. /* GetFont to Button mapping.
  112.  */
  113. struct TagItem getfont_map[] =
  114. {
  115.     { GETFONT_TextAttr, GA_TextAttr },
  116.     { GETFONT_FrontPen, BUTTON_TextPen },
  117.     { GETFONT_BackPen, BUTTON_BackgroundPen },
  118.     { GETFONT_SoftStyle, BUTTON_SoftStyle },
  119.     { TAG_DONE, TAG_DONE }
  120. };
  121.  
  122. /* SpeedBar help strings.  Also used in a ListBrowser.
  123.  */
  124. UBYTE *sbhelp_strs[] =
  125. {
  126.     "Erase block and copy it to the clipboard",
  127.     "Copy block to the clipboard",
  128.     "Paste from clipboard to your project",
  129.     "Erase block",
  130.     "Mail someone",
  131.     "Insert current time",
  132.     "Insert current date",
  133.     "Disk",
  134.     "Spray Paint",
  135.     "Print project",
  136.     NULL
  137. };
  138.  
  139. /* ListBrowser column info.
  140.  */
  141. struct ColumnInfo ci1[] =
  142. {
  143.     { 20, NULL, 0 },
  144.     { 80, NULL, 0 },
  145.     { -1, (STRPTR)~0, -1 }
  146. };
  147.  
  148. struct ColumnInfo ci2[] =
  149. {
  150.     { 100, "Column Header", 0 },
  151.     { -1, (STRPTR)~0, -1 }
  152. };
  153.  
  154. /* Some fonts that we'll be using.
  155.  */
  156. struct TextAttr helvetica15bu = { (STRPTR)"helvetica.font", 15, FSF_UNDERLINED | FSF_BOLD, FPF_DISKFONT };
  157. struct TextAttr garnet16 = { (STRPTR)"garnet.font", 16, 0, FPF_DISKFONT };
  158.  
  159.  
  160. /* Function prototypes.
  161.  */
  162. VOID set_mapping(struct Screen *, struct DrawInfo *, UWORD []);
  163. LONG easy_req(struct Window *, char *, char *, char *, ...);
  164. BOOL make_lb_list(struct List *, struct Image *, UBYTE **);
  165. VOID make_fancy_list(struct Gadget *);
  166. ULONG __asm __saveds lb_hook(register __a0 struct Hook *hook, register __a2 struct Node *node,
  167.                              register __a1 struct LBDrawMsg *msg);
  168. BOOL make_speedbar_list(struct List *, struct Image *, UBYTE **);
  169. VOID free_speedbar_list(struct List *);
  170.  
  171.  
  172. /* This is the start of our program.
  173.  */
  174. main()
  175. {
  176.     if (!ButtonBase) return(20);
  177.  
  178.     /* We'll just open up on the default public screen, so we need to get
  179.      * a lock on it.
  180.      */
  181.     if (screen = LockPubScreen(NULL))
  182.     {
  183.         struct DrawInfo *drinfo = GetScreenDrawInfo(screen);
  184.         struct Image *l;
  185.         UWORD mapping[8];
  186.  
  187.         /* Setup the pen mappings to use for our images.
  188.          */
  189.         set_mapping(screen, drinfo, mapping);
  190.  
  191.         /* Create a bunch of label lists that our various gadgets will
  192.          * use.
  193.          */
  194.         make_speedbar_list(&speedbar_list, sb_images, sbhelp_strs);
  195.         make_lb_list(&lb_list1, sb_images, sbhelp_strs);
  196.         NewList(&lb_list2);
  197.  
  198.         if (layout = LayoutObject,
  199.                         GA_DrawInfo, drinfo,
  200.                         LAYOUT_DeferLayout, TRUE,    /* Layout refreshes done on
  201.                                                      * task's context (by the
  202.                                                      * window class) */
  203.                         LAYOUT_SpaceOuter, TRUE,
  204.                         LAYOUT_BottomSpacing, 4,
  205.                         LAYOUT_HorizAlignment, LALIGN_RIGHT,
  206.                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  207.  
  208.                         LAYOUT_AddChild, LayoutObject,
  209.                             LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  210.  
  211.                             LAYOUT_AddChild, LayoutObject,
  212.                                 LAYOUT_BevelStyle, BVS_BUTTON,
  213.                                 LAYOUT_BevelState, IDS_SELECTED,
  214.                                 LAYOUT_VertAlignment, LALIGN_CENTRE,
  215.                                 LAYOUT_HorizAlignment, LALIGN_CENTRE,
  216.                                 LAYOUT_SpaceOuter, TRUE,
  217.                                 CLASSACT_BackFill, LAYERS_BACKFILL,
  218.  
  219.                                 /* "ClassAct Man", always visible.  This is a
  220.                                  * simple Label class image with a mapping.
  221.                                  */
  222.                                 LAYOUT_AddImage, l = LabelObject,
  223.                                     LABEL_Justification, LABEL_CENTRE,
  224.                                     LABEL_Mapping, mapping,
  225.                                     LABEL_Image, &picture_image,
  226.                                     LabelEnd,
  227.                                 CHILD_WeightedWidth, 0,
  228.                                 CHILD_WeightedHeight, 0,
  229.  
  230.                                 LayoutEnd,
  231.                             CHILD_WeightedWidth, 0,
  232.  
  233.                             LAYOUT_AddChild, layout1 = LayoutObject,
  234.                                 LAYOUT_LeftSpacing, 4,
  235.                                 LAYOUT_RightSpacing, 4,
  236.                                 LAYOUT_TopSpacing, 2,
  237.                                 LAYOUT_BottomSpacing, 2,
  238.                                 LAYOUT_BevelStyle, BVS_GROUP,
  239.  
  240.                                 /* All the cool stuff in this demo appears
  241.                                  * on different pages that we can flip
  242.                                  * through via some buttons at the bottom
  243.                                  * of the window.
  244.                                  */
  245.                                 LAYOUT_AddChild, page = PageObject,
  246.                                     /* The first page, showing our nifty
  247.                                      * logo.  This is a single label image,
  248.                                      * notice how you can seemlessly mix
  249.                                      * text and images, and also do pen
  250.                                      * re-mapping.
  251.                                      */
  252.                                     PAGE_Add, LayoutObject,
  253.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  254.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  255.  
  256.                                         LAYOUT_AddImage, l = LabelObject,
  257.                                             LABEL_DrawInfo, drinfo,
  258.                                             IA_Font, &helvetica15bu,
  259.                                             LABEL_Justification, LABEL_CENTRE,
  260.                                             LABEL_Text, "Welcome to the ClassAct Demo\n",
  261.                                             LABEL_Mapping, mapping,
  262.                                             LABEL_Image, &classact_image,
  263.                                             LabelEnd,
  264.                                         CHILD_WeightedWidth, 0,
  265.                                         CHILD_WeightedHeight, 0,
  266.  
  267.                                         LayoutEnd,
  268.  
  269.                                     /* A credits page, made up of a single
  270.                                      * label image.
  271.                                      */
  272.                                     PAGE_Add, LayoutObject,
  273.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  274.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  275.  
  276.                                         LAYOUT_AddImage, l = LabelObject,
  277.                                             LABEL_DrawInfo, drinfo,
  278.                                             IA_Font, &helvetica15bu,
  279.                                             LABEL_Justification, LABEL_CENTRE,
  280.                                             LABEL_Text, "Welcome to the ClassAct Demo\n",
  281.                                             IA_Font, screen->Font,
  282.                                             LABEL_Text, "\nPeople responsible for ClassAct:\n",
  283.                                             LABEL_Text, "Christopher Aldi\n",
  284.                                             LABEL_Text, "Timothy Aston\n",
  285.                                             LABEL_Text, "Osma Ahvenlampi\n\n",
  286.                                             LABEL_Text, "This demo written by Timothy Aston",
  287.                                             LabelEnd,
  288.                                         CHILD_WeightedWidth, 0,
  289.                                         CHILD_WeightedHeight, 0,
  290.  
  291.                                         LayoutEnd,
  292.  
  293.                                     /* The Button gadget class is so
  294.                                      * versatile, might as well dedicate
  295.                                      * an entire page to it.
  296.                                      */
  297.                                     PAGE_Add, LayoutObject,
  298.                                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  299.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  300.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  301.  
  302.                                         LAYOUT_AddImage, l = LabelObject,
  303.                                             LABEL_DrawInfo, drinfo,
  304.                                             IA_Font, &helvetica15bu,
  305.                                             LABEL_Justification, LABEL_CENTRE,
  306.                                             LABEL_Text, "ClassAct has buttons!",
  307.                                             LabelEnd,
  308.                                         CHILD_WeightedWidth, 0,
  309.                                         CHILD_WeightedHeight, 0,
  310.  
  311.                                         LAYOUT_AddChild, LayoutObject,
  312.                                             LAYOUT_AddChild, ButtonObject,
  313.                                                 GA_Text, "_Simple",
  314.                                                 GA_RelVerify, TRUE,
  315.                                                 ButtonEnd,
  316.  
  317.                                             LAYOUT_AddChild, ButtonObject,
  318.                                                 GA_Text, "Push Button",
  319.                                                 GA_RelVerify, TRUE,
  320.                                                 BUTTON_PushButton, TRUE,
  321.                                                 ButtonEnd,
  322.  
  323.                                             LAYOUT_AddChild, ButtonObject,
  324.                                                 GA_Text, "Colour",
  325.                                                 GA_RelVerify, TRUE,
  326.                                                 BUTTON_BackgroundPen, 7,
  327.                                                 BUTTON_TextPen, 2,
  328.                                                 ButtonEnd,
  329.  
  330.                                             LayoutEnd,
  331.  
  332.                                         LAYOUT_AddChild, LayoutObject,
  333.                                             LAYOUT_AddChild, ButtonObject,
  334.                                                 GA_Text, "B_old",
  335.                                                 GA_RelVerify, TRUE,
  336.                                                 BUTTON_SoftStyle, FSF_BOLD,
  337.                                                 ButtonEnd,
  338.  
  339.                                             LAYOUT_AddChild, ButtonObject,
  340.                                                 GA_Text, "Read-Only",
  341.                                                 GA_RelVerify, TRUE,
  342.                                                 GA_ReadOnly, TRUE,
  343.                                                 ButtonEnd,
  344.  
  345.                                             LAYOUT_AddChild, ButtonObject,
  346.                                                 GA_Text, "_Right aligned",
  347.                                                 GA_RelVerify, TRUE,
  348.                                                 BUTTON_Justification, BCJ_RIGHT,
  349.                                                 ButtonEnd,
  350.  
  351.                                             LayoutEnd,
  352.  
  353.                                         LAYOUT_AddChild, LayoutObject,
  354.                                             LAYOUT_AddChild, ButtonObject,
  355.                                                 GA_TextAttr, &garnet16,
  356.                                                 GA_Text, "B_ig Button, different font",
  357.                                                 GA_RelVerify, TRUE,
  358.                                                 ButtonEnd,
  359.                                             LayoutEnd,
  360.  
  361.                                         LAYOUT_AddChild, LayoutObject,
  362.                                             LAYOUT_VertAlignment, LALIGN_CENTRE,
  363.  
  364.                                             LAYOUT_AddChild, ButtonObject,
  365.                                                 BUTTON_AutoButton, BAG_POPFILE,
  366.                                                 GA_RelVerify, TRUE,
  367.                                                 ButtonEnd,
  368.                                             CHILD_WeightedWidth, 0,
  369.                                             CHILD_WeightedHeight, 0,
  370.                                             CHILD_Label, LabelObject,
  371.                                                 LABEL_Text, "Get Fi_le",
  372.                                                 LabelEnd,
  373.  
  374.                                             LAYOUT_AddChild, ButtonObject,
  375.                                                 BUTTON_AutoButton, BAG_POPDRAWER,
  376.                                                 GA_RelVerify, TRUE,
  377.                                                 ButtonEnd,
  378.                                             CHILD_WeightedWidth, 0,
  379.                                             CHILD_WeightedHeight, 0,
  380.                                             CHILD_Label, LabelObject,
  381.                                                 LABEL_Text, "Get _Drawer",
  382.                                                 LabelEnd,
  383.  
  384.                                             LAYOUT_AddChild, ButtonObject,
  385.                                                 BUTTON_AutoButton, BAG_POPFONT,
  386.                                                 GA_RelVerify, TRUE,
  387.                                                 ButtonEnd,
  388.                                             CHILD_WeightedWidth, 0,
  389.                                             CHILD_WeightedHeight, 0,
  390.                                             CHILD_Label, LabelObject,
  391.                                                 LABEL_Text, "Fo_nt",
  392.                                                 LabelEnd,
  393.  
  394.                                             LAYOUT_AddChild, ButtonObject,
  395.                                                 BUTTON_AutoButton, BAG_POPTIME,
  396.                                                 GA_RelVerify, TRUE,
  397.                                                 ButtonEnd,
  398.                                             CHILD_WeightedWidth, 0,
  399.                                             CHILD_WeightedHeight, 0,
  400.                                             CHILD_Label, LabelObject,
  401.                                                 LABEL_Text, "_Time",
  402.                                                 LabelEnd,
  403.  
  404.                                             LayoutEnd,
  405.                                         LayoutEnd,
  406.  
  407.                                     /* Our next page shows some gadgets
  408.                                      * that are basically just direct
  409.                                      * replacements for GadTools gadget
  410.                                      * kinds.  Don't be fooled though, even
  411.                                      * though they may look similar, we've
  412.                                      * made several useful enhancements.
  413.                                      */
  414.                                     PAGE_Add, LayoutObject,
  415.                                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  416.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  417.  
  418.                                         LAYOUT_AddImage, l = LabelObject,
  419.                                             LABEL_DrawInfo, drinfo,
  420.                                             IA_Font, &helvetica15bu,
  421.                                             LABEL_Justification, LABEL_CENTRE,
  422.                                             LABEL_Text, "GadTools Replacements",
  423.                                             LabelEnd,
  424.                                         CHILD_WeightedWidth, 0,
  425.                                         CHILD_WeightedHeight, 0,
  426.  
  427.                                         LAYOUT_AddChild, PaletteObject,
  428.                                             GA_RelVerify, TRUE,
  429.                                             PALETTE_NumColours, 1 << screen->RastPort.BitMap->Depth,
  430.                                             PaletteEnd,
  431.                                         CHILD_MinWidth, 40,
  432.                                         CHILD_MinHeight, 20,
  433.                                         CHILD_Label, LabelObject,
  434.                                             LABEL_Text, "_Palette",
  435.                                             LabelEnd,
  436.  
  437.                                         LAYOUT_AddChild, scroller_gad = ScrollerObject,
  438.                                             GA_RelVerify, TRUE,
  439.                                             SCROLLER_Top, 0,
  440.                                             SCROLLER_Total, 90,
  441.                                             SCROLLER_Visible, 10,
  442.                                             SCROLLER_Orientation, FREEHORIZ,
  443.                                             ScrollerEnd,
  444.                                         CHILD_MinHeight, 14,
  445.                                         CHILD_WeightedHeight, 0,
  446.                                         CHILD_Label, LabelObject,
  447.                                             LABEL_Text, "_Scroller",
  448.                                             LabelEnd,
  449.  
  450.                                         LAYOUT_AddChild, StringObject,
  451.                                             GA_RelVerify, TRUE,
  452.                                             STRINGA_MaxChars, 40,
  453.                                             STRINGA_TextVal, "ClassAct is just soooooo cool",
  454.                                             StringEnd,
  455.                                         CHILD_Label, LabelObject,
  456.                                             LABEL_Text, "S_tring",
  457.                                             LabelEnd,
  458.  
  459.                                         LAYOUT_AddChild, LayoutObject,
  460.                                             LAYOUT_AddChild, RadioButtonObject,
  461.                                                 GA_RelVerify, TRUE,
  462.                                                 GA_DrawInfo, drinfo,
  463.                                                 RADIOBUTTON_Labels, radio_list = RadioButtons("ClassAct radio buttons",
  464.                                                                                     "support strumming.",
  465.                                                                                     "Click & Drag over buttons!",
  466.                                                                                     NULL),
  467.                                                 RADIOBUTTON_Spacing, 2,
  468.                                                 RadioButtonEnd,
  469.  
  470.                                             LAYOUT_AddChild, CheckBoxObject,
  471.                                                 GA_RelVerify, TRUE,
  472.                                                 GA_Text, "_Click the label",
  473.                                                 CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  474.                                                 CheckBoxEnd,
  475.                                             LayoutEnd,
  476.                                         CHILD_WeightedHeight, 0,
  477.  
  478.                                         LayoutEnd,
  479.  
  480.                                     /* This page is a little more
  481.                                      * interesting, it contains some of the
  482.                                      * cooler classes like the fuelgauge,
  483.                                      * chooser and speedbar.  We also have
  484.                                      * an Integer class gadget, showing off
  485.                                      * our innovative arrow buttons.  This
  486.                                      * gadget is connected to the fuelgauge
  487.                                      * via a simple mapping.
  488.                                      */
  489.                                     PAGE_Add, LayoutObject,
  490.                                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  491.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  492.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  493.                                         
  494.                                         LAYOUT_AddImage, l = LabelObject,
  495.                                             LABEL_DrawInfo, drinfo,
  496.                                             IA_Font, &helvetica15bu,
  497.                                             LABEL_Justification, LABEL_CENTRE,
  498.                                             LABEL_Text, "New and Improved!\n",
  499.                                             LabelEnd,
  500.                                         CHILD_WeightedWidth, 0,
  501.                                         CHILD_WeightedHeight, 0,
  502.  
  503.                                         LAYOUT_AddChild, LayoutObject,
  504.                                             LAYOUT_SpaceOuter, FALSE,
  505.  
  506.                                             LAYOUT_AddChild, fuelgauge_gad = FuelGaugeObject,
  507.                                                 FUELGAUGE_Orientation, FGORIENT_HORIZ,
  508.                                                 FUELGAUGE_Percent, TRUE,
  509.                                                 FUELGAUGE_Min, 0,
  510.                                                 FUELGAUGE_Max, 100,
  511.                                                 FUELGAUGE_Level, 20,
  512.                                                 FUELGAUGE_Ticks, 10,
  513.                                                 FUELGAUGE_TickSize, 4,
  514.                                                 FUELGAUGE_ShortTicks, TRUE,
  515.                                                 FuelGaugeEnd,
  516.                                             CHILD_WeightedHeight, 0,
  517.                                             CHILD_Label, LabelObject,
  518.                                                 LABEL_DrawInfo, drinfo,
  519.                                                 LABEL_Text, "Interconnected:",
  520.                                                 LabelEnd,
  521.                                             LayoutEnd,
  522.  
  523.                                         LAYOUT_AddChild, LayoutObject,
  524.                                             LAYOUT_SpaceOuter, FALSE,
  525.  
  526.                                             LAYOUT_AddChild, IntegerObject,
  527.                                                 GA_RelVerify, TRUE,
  528.                                                 INTEGER_MaxChars, 3,
  529.                                                 INTEGER_Minimum, 0,
  530.                                                 INTEGER_Maximum, 100,
  531.                                                 INTEGER_Number, 20,
  532.                                                 INTEGER_MinVisible, 5,
  533.                                                 ICA_TARGET, fuelgauge_gad,
  534.                                                 ICA_MAP, integer_map,
  535.                                                 IntegerEnd,
  536.                                             CHILD_WeightedHeight, 0,
  537.                                             CHILD_WeightedWidth, 0,
  538.                                             CHILD_Label, LabelObject,
  539.                                                 LABEL_DrawInfo, drinfo,
  540.                                                 LABEL_Text, "_Look, arrows! (Range: 0...100):",
  541.                                                 LabelEnd,
  542.                                             LayoutEnd,
  543.  
  544.                                         LAYOUT_AddChild, LayoutObject,
  545.                                             LAYOUT_AddChild, ChooserObject,
  546.                                                 GA_RelVerify, TRUE,
  547.                                                 CHOOSER_Labels, chooser_list1 = ChooserLabels(    "A PopUp gadget",
  548.                                                                                     "from the Chooser",
  549.                                                                                     "gadget class.",
  550.                                                                                     "Good for allowing",
  551.                                                                                     "the user to",
  552.                                                                                     "select a state",
  553.                                                                                     "or mode.",
  554.                                                                                     NULL),
  555.                                                 CHOOSER_PopUp, TRUE,
  556.                                                 CHOOSER_AutoFit, TRUE,
  557.                                                 ChooserEnd,
  558.  
  559.                                             LAYOUT_AddChild, ChooserObject,
  560.                                                 GA_RelVerify, TRUE,
  561.                                                 CHOOSER_Labels, chooser_list2 = ChooserLabels("A DropDown",
  562.                                                                                     "gadget from",
  563.                                                                                     "the Chooser",
  564.                                                                                     "gadget class.",
  565.                                                                                     "Good for",
  566.                                                                                     "allowing the",
  567.                                                                                     "user to",
  568.                                                                                     "select actions",
  569.                                                                                     NULL),
  570.                                                 CHOOSER_DropDown, TRUE,
  571.                                                 CHOOSER_Title, "Drop-Down",
  572.                                                 CHOOSER_AutoFit, FALSE,
  573.                                                 ChooserEnd,
  574.  
  575.                                             LAYOUT_AddChild, ChooserObject,
  576.                                                 GA_RelVerify, TRUE,
  577.                                                 CHOOSER_Labels, chooser_list3 = ChooserLabels("A thin Chooser.",
  578.                                                                                 "Use this in",
  579.                                                                                 "conjunction with",
  580.                                                                                 "a string gadget.",
  581.                                                                                 NULL),
  582.                                                 CHOOSER_DropDown, TRUE,
  583.                                                 CHOOSER_AutoFit, TRUE,
  584.                                                 ChooserEnd,
  585.                                             CHILD_MinWidth, 20,
  586.                                             CHILD_WeightedWidth, 0,
  587.                                             LayoutEnd,
  588.                                         CHILD_WeightedWidth, 0,
  589.  
  590.                                         LAYOUT_AddChild, SpeedBarObject,
  591.                                             GA_RelVerify, TRUE,
  592.                                             SPEEDBAR_Orientation, SBORIENT_HORIZ,
  593.                                             SPEEDBAR_Buttons, &speedbar_list,
  594.                                             SPEEDBAR_Background, mapping[4],
  595.                                             SPEEDBAR_StrumBar, FALSE,
  596.                                             SpeedBarEnd,
  597.                                         CHILD_WeightedHeight, 0,
  598.  
  599.                                         LAYOUT_AddChild, ClickTabObject,
  600.                                             GA_RelVerify, TRUE,
  601.                                             CLICKTAB_Labels, tab_list = ClickTabs("Tabs", "For",
  602.                                                                             "Pages", "Etc.", NULL),
  603.                                             CLICKTAB_Current, 0L,
  604.                                             ClickTabEnd,
  605.                                         CHILD_WeightedHeight, 0,
  606.  
  607.                                         LayoutEnd,
  608.                                     CHILD_WeightedWidth, 0,
  609.  
  610.                                     /* One of the most powerful classes
  611.                                      * we've done is the ListBrowser.  The
  612.                                      * first object is a simple multi-
  613.                                      * column list showing images and text,
  614.                                      * as well as editable nodes.  The 2nd
  615.                                      * object is intended to demonstrate
  616.                                      * some of the numerous node attributes.
  617.                                      */
  618.                                     PAGE_Add, LayoutObject,
  619.                                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  620.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  621.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  622.  
  623.                                         LAYOUT_AddImage, l = LabelObject,
  624.                                             LABEL_DrawInfo, drinfo,
  625.                                             IA_Font, &helvetica15bu,
  626.                                             LABEL_Justification, LABEL_CENTRE,
  627.                                             LABEL_Text, "Look what ListBrowser can do!\n",
  628.                                             LabelEnd,
  629.                                         CHILD_WeightedWidth, 0,
  630.                                         CHILD_WeightedHeight, 0,
  631.  
  632.                                         LAYOUT_AddChild, LayoutObject,
  633.                                             LAYOUT_AddChild, ListBrowserObject,
  634.                                                 GA_RelVerify, TRUE,
  635.                                                 LISTBROWSER_Labels, (ULONG)&lb_list1,
  636.                                                 LISTBROWSER_ColumnInfo, &ci1,
  637.                                                 LISTBROWSER_AutoFit, TRUE,
  638.                                                 LISTBROWSER_MultiSelect, TRUE,
  639.                                                 LISTBROWSER_ShowSelected, TRUE,
  640.                                                 LISTBROWSER_Separators, TRUE,
  641.                                                 LISTBROWSER_Editable, TRUE,
  642.                                                 LISTBROWSER_Spacing, 1,
  643.                                                 ListBrowserEnd,
  644.  
  645.                                             LAYOUT_AddChild, lb_gad = ListBrowserObject,
  646.                                                 GA_RelVerify, TRUE,
  647.                                                 LISTBROWSER_Labels, &lb_list2,
  648.                                                 LISTBROWSER_ColumnInfo, &ci2,
  649.                                                 LISTBROWSER_ColumnTitles, TRUE,
  650.                                                 LISTBROWSER_Separators, TRUE,
  651.                                                 LISTBROWSER_Hierarchical, TRUE,
  652.                                                 LISTBROWSER_Editable, TRUE,
  653.                                                 LISTBROWSER_MultiSelect, TRUE,
  654.                                                 LISTBROWSER_ShowSelected, TRUE,
  655.                                                 ListBrowserEnd,
  656.                                             LayoutEnd,
  657.                                         LayoutEnd,
  658.  
  659.                                     /* Our second ListBrowser page shows
  660.                                      * the powerful hierarchical mode of
  661.                                      * ListBrowser.  The two gadgets
  662.                                      * contain identical lists, but the
  663.                                      * left-hand gadget shows the default
  664.                                      * hide/show images while the right-
  665.                                      * hand ones shows some custom images.
  666.                                      */
  667.                                     PAGE_Add, LayoutObject,
  668.                                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  669.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  670.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  671.  
  672.                                         LAYOUT_AddImage, l = LabelObject,
  673.                                             LABEL_DrawInfo, drinfo,
  674.                                             IA_Font, &helvetica15bu,
  675.                                             LABEL_Justification, LABEL_CENTRE,
  676.                                             LABEL_Text, "Get File/Font/Screen Mode\n",
  677.                                             IA_Font, screen->Font,
  678.                                             LABEL_Text, "ASL has never been this easy",
  679.                                             LabelEnd,
  680.                                         CHILD_WeightedWidth, 0,
  681.                                         CHILD_WeightedHeight, 0,
  682.  
  683.                                         LAYOUT_AddChild, getfile_gad = GetFileObject,
  684.                                             GA_ID, GAD_GETFILE,
  685.                                             GA_RelVerify, TRUE,
  686.                                             GETFILE_TitleText, "Select a File",
  687.                                             GETFILE_ReadOnly, FALSE,
  688.                                             End,
  689.                                         CHILD_WeightedHeight, 0,
  690.                                         CHILD_Label, LabelObject,
  691.                                             LABEL_Text, "File:",
  692.                                             LabelEnd,
  693.  
  694.                                         LAYOUT_AddChild, getfont_gad = GetFontObject,
  695.                                             GA_ID, GAD_GETFONT,
  696.                                             GA_RelVerify, TRUE,
  697.                                             GETFONT_TitleText, "Select a Font",
  698.                                             GETFONT_DoStyle, TRUE,
  699.                                             GETFONT_DoFrontPen, TRUE,
  700.                                             GETFONT_DoBackPen, TRUE,
  701.                                             ICA_MAP, getfont_map,
  702.                                             End,
  703.                                         CHILD_WeightedHeight, 0,
  704.                                         CHILD_Label, LabelObject,
  705.                                             LABEL_Text, "Font:",
  706.                                             LabelEnd,
  707.  
  708.                                         LAYOUT_AddChild, fontpreview_gad = ButtonObject,
  709.                                             GA_ReadOnly, TRUE,
  710.                                             GA_Text, "123 AcBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz!@#$%^&*()",
  711.                                             BUTTON_DomainString, "Text",
  712.                                             ButtonEnd,
  713.                                         CHILD_Label, LabelObject,
  714.                                             LABEL_Text, "Preview:",
  715.                                             LabelEnd,
  716.  
  717.                                         LAYOUT_AddChild, getscreen_gad = GetScreenModeObject,
  718.                                             GA_ID, GAD_GETSCREEN,
  719.                                             GA_RelVerify, TRUE,
  720.                                             GETSCREENMODE_TitleText, "Select a Screen Mode",
  721.                                             GETSCREENMODE_DoWidth, TRUE,
  722.                                             GETSCREENMODE_DoHeight, TRUE,
  723.                                             GETSCREENMODE_DoDepth, TRUE,
  724.                                             GETSCREENMODE_MinWidth, 500,
  725.                                             GETSCREENMODE_MinHeight, 180,
  726.                                             End,
  727.                                         CHILD_WeightedHeight, 0,
  728.                                         CHILD_Label, LabelObject,
  729.                                             LABEL_Text, "Screen Mode:",
  730.                                             LabelEnd,
  731.  
  732.                                         LayoutEnd,
  733.  
  734.                                     /* This is the last page, just the
  735.                                      * credits, again as a single label
  736.                                      * gadget.
  737.                                      */
  738.                                     PAGE_Add, LayoutObject,
  739.                                         LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  740.                                         LAYOUT_VertAlignment, LALIGN_CENTRE,
  741.                                         LAYOUT_HorizAlignment, LALIGN_CENTRE,
  742.  
  743.                                         LAYOUT_AddImage, l = LabelObject,
  744.                                             LABEL_DrawInfo, drinfo,
  745.                                             IA_Font, &helvetica15bu,
  746.                                             LABEL_Justification, LABEL_CENTRE,
  747.                                             LABEL_Text, "Order ClassAct Now!\n",
  748.                                             IA_Font, screen->Font,
  749.                                             LABEL_Text, "\nFinale Development, Inc.\n",
  750.                                             LABEL_Text, "P.O. Box 6905, ",
  751.                                             LABEL_Text, "West Palm Beach, FL 33405",
  752.                                             LABEL_Text, "U.S.A.\n",
  753.                                             LABEL_Text, "Tel: 1 (203) 235-7518\n",
  754.                                             LABEL_Text, "Fax: 1 (203) 237-8459\n",
  755.                                             LABEL_Text, "E-Mail: ClassAct@finale-dev.com\n",
  756.                                             LABEL_Text, "WWW: http://www.warped.com/~timmer/classact/\n",
  757.                                             LABEL_Text, "FTP: ftp.warped.com /pub/amiga/classact/\n",
  758.                                             LabelEnd,
  759.                                         CHILD_WeightedWidth, 0,
  760.                                         CHILD_WeightedHeight, 0,
  761.  
  762.                                         LayoutEnd,
  763.                                     LayoutEnd,
  764.  
  765.                                 PageEnd,
  766.  
  767.                             LayoutEnd,
  768.  
  769.                         /* These are the gadgets that appear at the
  770.                          * bottom of the window for changing pages.
  771.                          */
  772.                         LAYOUT_AddChild, layout2 = LayoutObject,
  773.                             LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  774.                             LAYOUT_EvenSize, TRUE,
  775.                             LAYOUT_HorizAlignment, LALIGN_RIGHT,
  776.                             LAYOUT_SpaceInner, FALSE,
  777.  
  778.                             LAYOUT_AddChild, SpaceObject,
  779.                                 SpaceEnd,
  780.                             CHILD_WeightedWidth, 0,
  781.                             CHILD_WeightedHeight, 0,
  782.  
  783.                             LAYOUT_AddChild, SpaceObject,
  784.                                 SpaceEnd,
  785.                             CHILD_WeightedWidth, 0,
  786.                             CHILD_WeightedHeight, 0,
  787.  
  788.                             LAYOUT_AddChild, back_gad = ButtonObject,
  789.                                 GA_ID, GAD_BACK,
  790.                                 GA_Text, "< _Back",
  791.                                 GA_RelVerify, TRUE,
  792.                                 GA_Disabled, TRUE,
  793.                                 ButtonEnd,
  794.                             CHILD_WeightedWidth, 0,
  795.                             CHILD_WeightedHeight, 0,
  796.  
  797.                             LAYOUT_AddChild, forward_gad = ButtonObject,
  798.                                 GA_ID, GAD_FORWARD,
  799.                                 GA_Text, "_Forward >",
  800.                                 GA_RelVerify, TRUE,
  801.                                 ButtonEnd,
  802.                             CHILD_WeightedWidth, 0,
  803.                             CHILD_WeightedHeight, 0,
  804.  
  805.                             LAYOUT_AddChild, SpaceObject,
  806.                                 SpaceEnd,
  807.                             CHILD_WeightedWidth, 0,
  808.                             CHILD_WeightedHeight, 0,
  809.  
  810.                             LAYOUT_AddChild, ButtonObject,
  811.                                 GA_ID, GAD_QUIT,
  812.                                 GA_Text, "Quit",
  813.                                 GA_RelVerify, TRUE,
  814.                                 ButtonEnd,
  815.                             CHILD_WeightedWidth, 0,
  816.                             CHILD_WeightedHeight, 0,
  817.  
  818.                             LayoutEnd,
  819.  
  820.                         CHILD_WeightedWidth, 0,
  821.                         CHILD_WeightedHeight, 0,
  822.  
  823.                         LayoutEnd)
  824.         {
  825.             struct MsgPort *app_port;
  826.             Object *window_obj;
  827.  
  828.             /* Connect the GetFont gadget to the font preview button.
  829.              */
  830.             SetAttrs(getfont_gad,
  831.                 ICA_TARGET, fontpreview_gad,
  832.                 TAG_DONE);
  833.  
  834.             /* Make the fancy ListBrowserList.
  835.              */
  836.             make_fancy_list(lb_gad);
  837.  
  838.             /* Create a message port for App* messages.  This is needed for
  839.              * iconification.  We're being a touch naughty by not checking
  840.              * the return code, but that just means that iconification won't
  841.              * work, nothing really bad will happen.
  842.              */
  843.             app_port = CreateMsgPort();
  844.  
  845.             /* Create the window object.
  846.              */
  847.             if (window_obj = WindowObject,
  848.                                 WA_Left, 0,
  849.                                 WA_Top, screen->Font->ta_YSize + 3,
  850.                                 WA_CustomScreen, screen,
  851.                                 WA_IDCMP, IDCMP_CLOSEWINDOW,
  852.                                 WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  853.                                             WFLG_SIZEGADGET | WFLG_ACTIVATE | WFLG_SMART_REFRESH,
  854.                                 WA_Title, "ClassAct Demonstration",
  855.                                 WINDOW_ParentGroup, layout,
  856.                                 WINDOW_IconifyGadget, TRUE,
  857.                                 WINDOW_Icon, GetDiskObject("PROGDIR:ClassActDemo"),
  858.                                 WINDOW_IconTitle, "ClassAct Demo",
  859.                                 WINDOW_AppPort, app_port,
  860.                                 EndWindow)
  861.             {
  862.                 struct Window *win;
  863.  
  864.                 /*  Open the window.
  865.                  */
  866.                 if (win = (struct Window *)CA_OpenWindow(window_obj))
  867.                 {
  868.                     ULONG signal;
  869.                     BOOL ok = TRUE;
  870.  
  871.                     /* Obtain the window wait signal mask.
  872.                      */
  873.                     GetAttr(WINDOW_SigMask, window_obj, &signal);
  874.  
  875.                     /* Input Event Loop
  876.                      */
  877.                     while (ok)
  878.                     {
  879.                         ULONG result;
  880.  
  881.                         Wait(signal | (1L << app_port->mp_SigBit));
  882.  
  883.                         /* CA_HandleInput() returns the gadget ID of a clicked
  884.                          * gadget, or one of several pre-defined values.  For
  885.                          * this demo, we're only actually interested in a
  886.                          * close window and a couple of gadget clicks.
  887.                          */
  888.                         while ((result = CA_HandleInput(window_obj, NULL)) != WMHI_LASTMSG)
  889.                         {
  890.                             ULONG current_page;
  891.  
  892.                             switch(result & WMHI_CLASSMASK)
  893.                             {
  894.                                 case WMHI_CLOSEWINDOW:
  895.                                     ok = FALSE;
  896.                                     break;
  897.     
  898.                                 case WMHI_GADGETUP:
  899.                                     switch (result & WMHI_GADGETMASK)
  900.                                     {
  901.                                         case GAD_FORWARD:
  902.                                             GetAttr(PAGE_Current, page, ¤t_page);
  903.                                             if (current_page < NUM_PAGES)
  904.                                             {
  905.                                                 if (current_page == 0)
  906.                                                     if (SetGadgetAttrs(back_gad, win, NULL,
  907.                                                             GA_Disabled, FALSE,
  908.                                                             TAG_DONE))
  909.                                                         RefreshGList(layout2, win, NULL, 1);
  910.         
  911.                                                 current_page++;
  912.         
  913.                                                 if (current_page == NUM_PAGES)
  914.                                                     if (SetGadgetAttrs(forward_gad, win, NULL,
  915.                                                             GA_Disabled, TRUE,
  916.                                                             TAG_DONE))
  917.                                                         RefreshGList(layout2, win, NULL, 1);
  918.         
  919.                                                 SetGadgetAttrs(page, win, NULL,
  920.                                                     PAGE_Current, current_page,
  921.                                                     TAG_DONE);
  922.                                                 RethinkLayout(layout1, win, NULL, TRUE);
  923.                                             }
  924.                                             break;
  925.  
  926.                                         case GAD_GETFILE:
  927.                                             RequestFile((Object *)getfile_gad, win);
  928.                                             break;
  929.  
  930.                                         case GAD_GETFONT:
  931.                                             RequestFont((Object *)getfont_gad, win);
  932.                                             break;
  933.  
  934.                                         case GAD_GETSCREEN:
  935.                                             RequestScreenMode((Object *)getscreen_gad, win);
  936.                                             break;
  937.  
  938.                                         case GAD_BACK:
  939.                                             GetAttr(PAGE_Current, page, ¤t_page);
  940.                                             if (current_page > 0)
  941.                                             {
  942.                                                 if (current_page == NUM_PAGES)
  943.                                                     if (SetGadgetAttrs(forward_gad, win, NULL,
  944.                                                             GA_Disabled, FALSE,
  945.                                                             TAG_DONE))
  946.                                                         RefreshGList(layout2, win, NULL, 1);
  947.         
  948.                                                 current_page--;
  949.         
  950.                                                 if (current_page == 0)
  951.                                                     if (SetGadgetAttrs(back_gad, win, NULL,
  952.                                                             GA_Disabled, TRUE,
  953.                                                             TAG_DONE))
  954.                                                         RefreshGList(layout2, win, NULL, 1);
  955.         
  956.                                                 SetGadgetAttrs(page, win, NULL,
  957.                                                     PAGE_Current, current_page,
  958.                                                     TAG_DONE);
  959.                                                 RethinkLayout(layout1, win, NULL, TRUE);
  960.                                             }
  961.                                             break;
  962.  
  963.                                         case GAD_QUIT:
  964.                                             ok = FALSE;
  965.                                             break;
  966.  
  967.                                         default:
  968.                                             break;
  969.                                     }
  970.                                     break;
  971.                                 
  972.                                 case WMHI_ICONIFY:
  973.                                     if (CA_Iconify(window_obj))
  974.                                         win = NULL;
  975.                                     break;
  976.                                  
  977.                                 case WMHI_UNICONIFY:
  978.                                     win = CA_OpenWindow(window_obj);
  979.                                     break;
  980.  
  981.                                 default:
  982.                                     break;
  983.                             }
  984.                         }
  985.                     }
  986.  
  987.                     /* Disposing of the window object will also close the
  988.                      * window if it is already opened and it will dispose of
  989.                      * all objects attached to it.
  990.                      */
  991.                     DisposeObject(window_obj);
  992.                 }
  993.                 else
  994.                     easy_req(NULL, "Demo failed to start\nCouldn't open window", "Quit", "");
  995.  
  996.                 /* Lose the App* message port.
  997.                  */
  998.                 if (app_port)
  999.                     DeleteMsgPort(app_port);
  1000.             }
  1001.             else
  1002.             {
  1003.                 easy_req(NULL, "Demo failed to start\nCouldn't create window object", "Quit", "");
  1004.                 DisposeObject(layout);
  1005.             }
  1006.         }
  1007.         else
  1008.             easy_req(NULL, "Demo failed to start\nCouldn't create layout", "Quit", "");
  1009.  
  1010.         /* Free the lists.
  1011.          */
  1012.         if (radio_list)
  1013.             FreeRadioButtons(radio_list);
  1014.         if (chooser_list1)
  1015.             FreeChooserLabels(chooser_list1);
  1016.         if (chooser_list2)
  1017.             FreeChooserLabels(chooser_list2);
  1018.         if (chooser_list3)
  1019.             FreeChooserLabels(chooser_list3);
  1020.         if (tab_list)
  1021.             FreeClickTabs(tab_list);
  1022.  
  1023.         free_speedbar_list(&speedbar_list);
  1024.  
  1025.         FreeListBrowserList(&lb_list1);
  1026.         FreeListBrowserList(&lb_list2);
  1027.         DisposeObject(limage);
  1028.  
  1029.         if (screen->RastPort.BitMap->Depth > 2 && GfxBase->LibNode.lib_Version >= 39)
  1030.         {
  1031.             ReleasePen(screen->ViewPort.ColorMap, mapping[4]);
  1032.             ReleasePen(screen->ViewPort.ColorMap, mapping[5]);
  1033.             ReleasePen(screen->ViewPort.ColorMap, mapping[7]);
  1034.         }
  1035.  
  1036.         UnlockPubScreen(0, screen);
  1037.     }
  1038.     else
  1039.         easy_req(NULL, "Demo failed to start\nCouldn't lock destination screen", "Quit", "");
  1040. }
  1041.  
  1042.  
  1043. /* Set the mapping array for a screen.  This creates an 8 colour mapping
  1044.  * that should closely match the style of 8-colour palette that has become
  1045.  * more or less conventional:
  1046.  *     pen 0 - medium grayish tone
  1047.  *     pen 1 - black
  1048.  *     pen 2 - white
  1049.  *     pen 3 - an arbitrary colour
  1050.  *     pen 4 - darker tone of pen 0
  1051.  *     pen 5 - lighter tone of pen 0
  1052.  *     pen 6,7 - some nice colours.
  1053.  * You can be reasonably sure that this routine will setup a mapping that
  1054.  * will make images designed for this style of palette look OK.
  1055.  *
  1056.  * This should probably lock the pen it eventually chooses, and maybe try to
  1057.  * allocate a pen if it can't find anything close enough.
  1058.  */
  1059. VOID set_mapping(struct Screen *screen, struct DrawInfo *drinfo, UWORD image_mapping[])
  1060. {
  1061.     /* Setup the image remapping.
  1062.      */
  1063.     image_mapping[0] = drinfo->dri_Pens[BACKGROUNDPEN];
  1064.     image_mapping[1] = drinfo->dri_Pens[SHADOWPEN];
  1065.     image_mapping[2] = drinfo->dri_Pens[SHINEPEN];
  1066.     image_mapping[3] = drinfo->dri_Pens[FILLPEN];
  1067.  
  1068.     if (screen->RastPort.BitMap->Depth > 2)
  1069.     {
  1070.         if (GfxBase->LibNode.lib_Version >= 39)
  1071.         {
  1072.             struct ColorMap *colourmap = screen->ViewPort.ColorMap;
  1073.             ULONG bg[3];
  1074.  
  1075.             GetRGB32(colourmap, drinfo->dri_Pens[BACKGROUNDPEN], 1, bg);
  1076.             image_mapping[4] = ObtainBestPen(colourmap, bg[0] - 0x22222222, bg[1] - 0x22222222, bg[2] - 0x22222222,
  1077.                                     OBP_Precision, PRECISION_GUI);
  1078.             image_mapping[5] = ObtainBestPen(colourmap, bg[0] + 0x22222222, bg[1] + 0x22222222, bg[2] + 0x22222222,
  1079.                                     OBP_Precision, PRECISION_GUI);
  1080.             image_mapping[7] = ObtainBestPen(colourmap, 0xeeeeeeee, 0x22222222, 0x22222222,
  1081.                                     OBP_Precision, PRECISION_GUI);
  1082.         }
  1083.         else
  1084.         {
  1085.             UWORD bg;
  1086.             WORD lightgray, darkgray;
  1087.             WORD rdiff1 = 3, gdiff1 = 3, bdiff1 = 3;
  1088.             WORD rdiff2 = 3, gdiff2 = 3, bdiff2 = 3;
  1089.             WORD i;
  1090.  
  1091.             /* Set the defaults.
  1092.              */
  1093.             lightgray = darkgray = drinfo->dri_Pens[BACKGROUNDPEN];
  1094.  
  1095.             /* Find out what the background colour is.
  1096.              */
  1097.             bg = GetRGB4(screen->ViewPort.ColorMap, 0);
  1098.  
  1099.             /* Search for the light and dark grays.
  1100.              */
  1101.             for (i = 1; i < 1 << screen->RastPort.BitMap->Depth; i++)
  1102.             {
  1103.                 UWORD colour;
  1104.  
  1105.                 /* Get the colour.
  1106.                  */
  1107.                 colour = GetRGB4(screen->ViewPort.ColorMap, i);
  1108.  
  1109.                 /* Compare it to the background colour, see if its darker and
  1110.                  * close enough to that colour.
  1111.                  */
  1112.                 if ((RED(bg) >= RED(colour) && RED(bg) - RED(colour) <= rdiff1) &&
  1113.                     (GREEN(bg) >= GREEN(colour) && GREEN(bg) - GREEN(colour) <= gdiff1) &&
  1114.                     (BLUE(bg) >= BLUE(colour) && BLUE(bg) - BLUE(colour) <= bdiff1))
  1115.                 {
  1116.                     darkgray = i;
  1117.                     rdiff1 = RED(bg) - RED(colour);
  1118.                     gdiff1 = GREEN(bg) - GREEN(colour);
  1119.                     bdiff1 = BLUE(bg) - BLUE(colour);
  1120.                 }
  1121.                 /* Compare it to the background colour, see if its lighter and
  1122.                  * close enough to that colour.
  1123.                  */
  1124.                 if ((RED(colour) >= RED(bg) && RED(colour) - RED(bg) <= rdiff2) &&
  1125.                     (GREEN(colour) >= GREEN(bg) && GREEN(colour) - GREEN(bg) <= gdiff2) &&
  1126.                     (BLUE(colour) >= BLUE(bg) && BLUE(colour) - BLUE(bg) <= bdiff2))
  1127.                 {
  1128.                     lightgray = i;
  1129.                     rdiff2 = RED(colour) - RED(bg);
  1130.                     gdiff2 = GREEN(colour) - GREEN(bg);
  1131.                     bdiff2 = BLUE(colour) - BLUE(bg);
  1132.                 }
  1133.             }
  1134.  
  1135.             image_mapping[4] = darkgray;
  1136.             image_mapping[5] = lightgray;
  1137.             image_mapping[6] = (1 << screen->RastPort.BitMap->Depth) - 2;
  1138.             image_mapping[7] = (1 << screen->RastPort.BitMap->Depth) - 1;
  1139.         }
  1140.     }
  1141.     else
  1142.     {
  1143.         image_mapping[4] = image_mapping[5] = drinfo->dri_Pens[BACKGROUNDPEN];
  1144.         image_mapping[6] = image_mapping[7] = drinfo->dri_Pens[FILLPEN];
  1145.     }
  1146. }
  1147.  
  1148.  
  1149. /* Do an easy requester.
  1150.  */
  1151. LONG easy_req(struct Window *win, char *reqtext, char *reqgads, char *reqargs, ...)
  1152. {
  1153.     struct EasyStruct general_es =
  1154.     {
  1155.         sizeof(struct EasyStruct),
  1156.         0,
  1157.         "Demo",
  1158.         NULL,
  1159.         NULL
  1160.     };
  1161.  
  1162.     general_es.es_TextFormat = reqtext;
  1163.     general_es.es_GadgetFormat = reqgads;
  1164.  
  1165.     return(EasyRequestArgs(win, &general_es, NULL, &reqargs));
  1166. }
  1167.  
  1168.  
  1169. /* Function to make an Exec List of ListBrowserNodes from an array of images
  1170.  * and an array of strings.
  1171.  */
  1172. BOOL make_lb_list(struct List *list, struct Image *images, UBYTE **strs)
  1173. {
  1174.     struct Node *node;
  1175.     WORD i = 0;
  1176.  
  1177.     NewList(list);
  1178.  
  1179.     while (i < 10)
  1180.     {
  1181.         if (node = AllocListBrowserNode(2,
  1182.                         LBNA_Column, 0,
  1183.                             LBNCA_Image, images,
  1184.                             LBNCA_Justification, LCJ_CENTRE,
  1185.                         LBNA_Column, 1,
  1186.                             LBNCA_CopyText, TRUE,
  1187.                             LBNCA_Text, *strs,
  1188.                             LBNCA_Editable, TRUE,
  1189.                             LBNCA_MaxChars, 60,
  1190.                         TAG_DONE))
  1191.         {
  1192.             AddTail(list, node);
  1193.         }
  1194.         else
  1195.             break;
  1196.  
  1197.         images++;
  1198.         strs++;
  1199.         i++;
  1200.     }
  1201.     return(TRUE);
  1202. }
  1203.  
  1204.  
  1205. /* Make a fairly fancy list.  We've taken a different approach here, this
  1206.  * time using ListBrowser methods to create the list items AFTER the object
  1207.  * has been created.
  1208.  */
  1209. VOID make_fancy_list(struct Gadget *lb_gad)
  1210. {
  1211.     struct Image *gimage;
  1212.     static struct Hook lbhook;
  1213.  
  1214.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1215.         LBNA_Generation, 1,
  1216.         LBNA_Column, 0,
  1217.             LBNCA_CopyText, TRUE,
  1218.             LBNCA_Text, "Demo of ListBrowserNode features",
  1219.         TAG_DONE);
  1220.  
  1221.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1222.         LBNA_Generation, 1,
  1223.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1224.         LBNA_Column, 0,
  1225.             LBNCA_CopyText, TRUE,
  1226.             LBNCA_Text, "Editable node",
  1227.         TAG_DONE);
  1228.  
  1229.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1230.         LBNA_Generation, 2,
  1231.         LBNA_Column, 0,
  1232.             LBNCA_CopyText, TRUE,
  1233.             LBNCA_Text, "Click twice to edit",
  1234.             LBNCA_Editable, TRUE,
  1235.             LBNCA_MaxChars, 60,
  1236.         TAG_DONE);
  1237.  
  1238.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1239.         LBNA_Generation, 1,
  1240.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1241.         LBNA_Column, 0,
  1242.             LBNCA_CopyText, TRUE,
  1243.             LBNCA_Text, "Change colours",
  1244.         TAG_DONE);
  1245.  
  1246.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1247.         LBNA_Generation, 2,
  1248.         LBNA_Flags, LBFLG_CUSTOMPENS,
  1249.         LBNA_Column, 0,
  1250.             LBNCA_CopyText, TRUE,
  1251.             LBNCA_Text, "Colourful!",
  1252.             LBNCA_FGPen, 19,
  1253.             LBNCA_BGPen, 18,
  1254.         TAG_DONE);
  1255.  
  1256.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1257.         LBNA_Generation, 1,
  1258.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1259.         LBNA_Column, 0,
  1260.             LBNCA_CopyText, TRUE,
  1261.             LBNCA_Text, "Checkbox item",
  1262.         TAG_DONE);
  1263.  
  1264.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1265.         LBNA_Generation, 2,
  1266.         LBNA_CheckBox, TRUE,
  1267.         LBNA_Checked, TRUE,
  1268.         LBNA_Column, 0,
  1269.             LBNCA_CopyText, TRUE,
  1270.             LBNCA_Text, "Checked by default",
  1271.         TAG_DONE);
  1272.  
  1273.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1274.         LBNA_Generation, 2,
  1275.         LBNA_CheckBox, TRUE,
  1276.         LBNA_Checked, FALSE,
  1277.         LBNA_Column, 0,
  1278.             LBNCA_CopyText, TRUE,
  1279.             LBNCA_Text, "Unchecked by default",
  1280.         TAG_DONE);
  1281.  
  1282.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1283.         LBNA_Generation, 1,
  1284.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1285.         LBNA_Column, 0,
  1286.             LBNCA_CopyText, TRUE,
  1287.             LBNCA_Text, "Justifications",
  1288.         TAG_DONE);
  1289.  
  1290.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1291.         LBNA_Generation, 2,
  1292.         LBNA_Column, 0,
  1293.             LBNCA_CopyText, TRUE,
  1294.             LBNCA_Text, "Left",
  1295.             LBNCA_Justification, LCJ_LEFT,
  1296.         TAG_DONE);
  1297.  
  1298.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1299.         LBNA_Generation, 2,
  1300.         LBNA_Column, 0,
  1301.             LBNCA_CopyText, TRUE,
  1302.             LBNCA_Text, "Centre",
  1303.             LBNCA_Justification, LCJ_CENTRE,
  1304.         TAG_DONE);
  1305.  
  1306.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1307.         LBNA_Generation, 2,
  1308.         LBNA_Column, 0,
  1309.             LBNCA_CopyText, TRUE,
  1310.             LBNCA_Text, "Right",
  1311.             LBNCA_Justification, LCJ_RIGHT,
  1312.         TAG_DONE);
  1313.  
  1314.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1315.         LBNA_Generation, 1,
  1316.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1317.         LBNA_Column, 0,
  1318.             LBNCA_CopyText, TRUE,
  1319.             LBNCA_Text, "Read-Only node",
  1320.         TAG_DONE);
  1321.  
  1322.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1323.         LBNA_Generation, 2,
  1324.         LBNA_Flags, LBFLG_READONLY,
  1325.         LBNA_Column, 0,
  1326.             LBNCA_CopyText, TRUE,
  1327.             LBNCA_Text, "Can't select me!",
  1328.         TAG_DONE);
  1329.  
  1330.     gimage = GlyphObject,
  1331.                 IA_Width, 20,
  1332.                 IA_Height, 20,
  1333.                 GLYPH_Glyph, GLYPH_POPTIME,
  1334.                 GlyphEnd;
  1335.     limage = LabelObject,
  1336.                 IA_Font, &garnet16,
  1337.                 LABEL_Text, "Created using\n_label.image\n",
  1338.                 IA_Font, screen->Font,
  1339.                 LABEL_SoftStyle, FSF_BOLD | FSF_ITALIC,
  1340.                 LABEL_DisposeImage, TRUE,
  1341.                 LABEL_Image, gimage,
  1342.                 IA_FGPen, 35,
  1343.                 LABEL_Text, " Cool eh?",
  1344.                 LabelEnd;
  1345.  
  1346.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1347.         LBNA_Generation, 1,
  1348.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1349.         LBNA_Column, 0,
  1350.             LBNCA_CopyText, TRUE,
  1351.             LBNCA_Text, "Some images",
  1352.         TAG_DONE);
  1353.  
  1354.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1355.         LBNA_Generation, 2,
  1356.         LBNA_Column, 0,
  1357.             LBNCA_Image, limage,
  1358.         TAG_DONE);
  1359.  
  1360.     lbhook.h_Entry = (ULONG (*)())lb_hook;
  1361.     lbhook.h_SubEntry = NULL;
  1362.     lbhook.h_Data = NULL;
  1363.  
  1364.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1365.         LBNA_Generation, 1,
  1366.         LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  1367.         LBNA_Column, 0,
  1368.             LBNCA_CopyText, TRUE,
  1369.             LBNCA_Text, "Rendering hook",
  1370.         TAG_DONE);
  1371.  
  1372.     LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  1373.         LBNA_Generation, 2,
  1374.         LBNA_Column, 0,
  1375.             LBNCA_RenderHook, &lbhook,
  1376.             LBNCA_HookHeight, 20,
  1377.         TAG_DONE);
  1378. }
  1379.  
  1380. /* Hook for our fancy list.  This just renders an ellipse.
  1381.  */
  1382. ULONG __asm __saveds lb_hook(register __a0 struct Hook *hook, register __a2 struct Node *node,
  1383.                              register __a1 struct LBDrawMsg *msg)
  1384. {
  1385.     WORD width = msg->lbdm_Bounds.MaxX - msg->lbdm_Bounds.MinX;
  1386.     WORD height = msg->lbdm_Bounds.MaxY - msg->lbdm_Bounds.MinY;
  1387.  
  1388.     if(msg->lbdm_MethodID != LV_DRAW)
  1389.         return(LBCB_UNKNOWN);
  1390.  
  1391.     SetAPen(msg->lbdm_RastPort, 69);
  1392.     DrawEllipse(msg->lbdm_RastPort,
  1393.         msg->lbdm_Bounds.MinX + (width / 2), msg->lbdm_Bounds.MinY + (height / 2),
  1394.         width / 2, height / 2);
  1395.         
  1396.     return(LVCB_OK);
  1397. }
  1398.  
  1399. /* Create the SpeedBar list from an array of images, creating help texts
  1400.  * for each button from a string array.
  1401.  */
  1402. BOOL make_speedbar_list(struct List *list, struct Image *images, UBYTE **help)
  1403. {
  1404.     struct Node *node;
  1405.     WORD i = 0;
  1406.  
  1407.     NewList(list);
  1408.  
  1409.     while (i < 10)
  1410.     {
  1411.         if (node = AllocSpeedButtonNode(i,
  1412.                         SBNA_Image, images,
  1413.                         SBNA_Top, 2,
  1414.                         SBNA_Left, 0,
  1415.                         SBNA_Help, *help,
  1416.                         SBNA_Enabled, TRUE,
  1417.                         SBNA_Spacing, 2,
  1418.                         SBNA_Highlight, SBH_RECESS,
  1419.                         TAG_DONE))
  1420.         {
  1421.             AddTail(list, node);
  1422.         }
  1423.         else
  1424.             PutStr("Allocation failed\n");
  1425.  
  1426.         images++;
  1427.         help++;
  1428.         i++;
  1429.     }
  1430.     return(TRUE);
  1431. }
  1432.  
  1433.  
  1434. /* Function to free a SpeedBar Exec List.
  1435.  */
  1436. VOID free_speedbar_list(struct List *list)
  1437. {
  1438.     struct Node *node, *nextnode;
  1439.  
  1440.     node = list->lh_Head;
  1441.     while (nextnode = node->ln_Succ)
  1442.     {
  1443.         FreeSpeedButtonNode(node);
  1444.         node = nextnode;
  1445.     }
  1446.     NewList(list);
  1447. }
  1448.